//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XAppPopup.cpp>
///	@path	~/src/appear/xwin/
///	@date	2008/10/13
///	@brief	.

#define _FULLAPI
#include "config/config.h"

#include "graphics/IRenderer.h"

#include "gui/composite/composition.h"
#include "gui/composite/CCompositeTexture.h"

#include "appear/xwin/XAppPopup.h"

namespace xeres {

	IMPL_IOBJECT_CLASS_DYNAMIC( XAppPopup );

	// XAppPopup
	XAppPopup::XAppPopup( void )
		: XAppFrame()
	{
	}

	// XAppPopup
	XAppPopup::XAppPopup( const Rect<int>& placement )
		: XAppFrame( placement )
	{
	}

	// XAppPopup
	XAppPopup::XAppPopup( const Pair<int>& size )
		: XAppFrame( size )
	{
	}

	// ~XAppPopup
	XAppPopup::~XAppPopup( void )
	{
	}

	// OnFocusIn
	void XAppPopup::OnFocusIn( Updater& updater , RefWeak<IGuiComp> last )
	{
		__super::OnFocusIn( updater , last );
	}

	// OnFocusOut
	void XAppPopup::OnFocusOut( Updater& updater , RefWeak<IGuiComp> next )
	{
		__super::OnFocusOut( updater , next );
		if( next != m_subPopup )
		{
			RefWeak<XDesktop> parent = GetParent();
			parent->ShowWindow( this , false , true );
		}
	}

	// OnDrawBackground
	void XAppPopup::OnDrawBackground( Composition& composition )
	{
		if( m_background.IsValid() )
		{
			composition.painter().StcBitmap( m_background , Pair<int>(0,0) , GetBound() , 255 , 0 , m_edge.x , m_edge.y );
		}
	}

	// SetBackground
	void XAppPopup::SetBackground( Ref<IBitmap> bitmap , const Pair<int>& edge )
	{
		m_background = bitmap;
		m_aeroEdge = m_edge = edge;
	}
	// SetBackground
	void XAppPopup::SetBackground( Ref<IBitmap> bitmap , const Pair<int>& edge , const Pair<int>& aeroEdge )
	{
		m_background = bitmap;
		m_edge = edge;
		m_aeroEdge = aeroEdge;
	}
	// OnComposite
	void XAppPopup::OnComposite( RenderContext& rc , FrameComposition& fc )
	{
		Rect<int> dest( GetPlacement() );
		dest.extend( -m_aeroEdge );
		if( m_background.IsNull() || m_effect.IsValid() )
		{
			fc.DrawFrame( rc , GetPlacement() , m_texture , m_effect );
		}
		else
		{
			//fc.DrawFrame( rc , GetPlacement() , m_texture , NULL );
			fc.AeroCompositeFrame( rc , GetPlacement() , m_texture , dest );
		}
	}

} // namespace xeres
